package org.new9uy.tetris.util;

import java.util.Arrays;

import org.new9uy.tetris.game.player.Player;
import org.new9uy.tetris.model.Mino;

public class ArrayUtils
{

    public static void reverse(int[] a)
    {
        int mid = a.length / 2;

        for (int i = 0; i < mid; i++)
        {
            int swapper = a[i];
            a[i] = a[a.length - 1 - i];
            a[a.length - 1 - i] = swapper;
        }
    }

    public static int[] noDups(int[] a)
    {
        int[] temp = new int[4];
        int length = 0;
        boolean in = false;
        for (int j = 0; j < 4; j++)
        {
            for (int t = 0; t < 4; t++)
            {
                if (a[j] == temp[t])
                {
                    in = true;
                }
            }
            if (!in)
            {
                temp[length] = a[j];
                length = length + 1;
            } else
            {
                in = false;
            }
        }

        return temp.clone();
    }

    public static void sortAscending(int[] a)
    {
        Arrays.sort(a);
    }

    public static void sortDescending(int[] a)
    {
        Arrays.sort(a);
        reverse(a);
    }

    public static Mino[] duplicate(Mino[] mino)
    {
        return mino.clone();
    }

    public static void dispIntArray(int[] arr)
    {
        System.out.print("\n" + arr.length + ":  [");
        for (int i = 0; i < arr.length; i++)
        {
            System.out.print(arr[i] + " ");
        }
        System.out.print("]");
    }

    public static void dispMinoArray(Mino[] arr)
    {
        System.out.print("\n" + arr.length + ":  [");
        for (int i = 0; i < arr.length; i++)
        {
            System.out.print(arr[i].coordinates() + " ");
        }
        System.out.print("]");
    }
}
